//
//  ProductListCollectionViewCell.swift
//  CJXSwiftStoryboard
//
//  Created by CJX on 2016/10/20.
//  Copyright © 2016年 caijianxi. All rights reserved.
//

import UIKit

class ProductListCollectionViewCell: UICollectionViewCell {
    
    var myImageView = UIImageView()
    var titleLabel = UILabel()
    var priceLabel = UILabel()
    
    
    
    
    var model : ProductModel?{
        didSet{
            
            myImageView.sd_setImageWithURL(NSURL(string: (model?.products_image)!), placeholderImage: nil)
            
            titleLabel.text = model?.products_name
            
            priceLabel.text = model?.products_price
            
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: CGRectMake(0, 0,(SCREEN_WIDTH-15)/2, (SCREEN_WIDTH-15)/2*1.4))
        
        
        myImageView.frame = CGRectMake(0, 0, (SCREEN_WIDTH-15)/2, (SCREEN_WIDTH-15)/2)
        myImageView.contentMode = .ScaleAspectFit
        myImageView.clipsToBounds = true
        self.addSubview(myImageView)
        
        titleLabel.frame = CGRectMake(0, (SCREEN_WIDTH-15)/2 + 5, (SCREEN_WIDTH-15)/2, (SCREEN_WIDTH-15)/2*0.3-10)
        titleLabel.font = UIFont.systemFontOfSize(12)
        titleLabel.textColor = UIColor.grayColor()
        titleLabel.numberOfLines = 0
        self.addSubview(titleLabel)
        
        if SCREEN_WIDTH == 320 {
            titleLabel.font = UIFont.systemFontOfSize(9)
        }else if SCREEN_WIDTH > 320 && SCREEN_WIDTH < 430{
            titleLabel.font = UIFont.systemFontOfSize(11)
        }else{
            titleLabel.font = UIFont.systemFontOfSize(13)
        }
        
        priceLabel.frame = CGRectMake(0, (SCREEN_WIDTH-15)/2*1.3, (SCREEN_WIDTH-15)/2, (SCREEN_WIDTH-15)/2*0.1)
        priceLabel.textAlignment = .Center
        self.addSubview(priceLabel)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
